//
//  DashedLineView.m
//  JPWords
//
//  Created by 梁淑婷 on 2024/7/31.
//

#import "DashedLineView.h"

@implementation DashedLineView

- (void)drawRect:(CGRect)rect {
    // 绘制背景色
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
    CGContextFillRect(context, rect);
    
    // 绘制虚线
    CGContextSetStrokeColorWithColor(context, KLineColor.CGColor);
    CGContextSetLineWidth(context, 1.0);
    
    CGFloat dashPattern[] = {2.0, 2.0}; // 2 points on, 2 points off
    CGContextSetLineDash(context, 0.0, dashPattern, 2); // 2 is the number of elements in the dashPattern array
    
    CGContextMoveToPoint(context, 0, CGRectGetHeight(self.frame) / 2);
    CGContextAddLineToPoint(context, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame) / 2);
    
    CGContextStrokePath(context);
}

@end
